package com.weaver.shuiguict.action;

import weaver.conn.RecordSet;
import weaver.docs.docs.DocManager;
import weaver.docs.docs.ShareManageDocOperation;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

public class ChangeDocStatusnwjhAction implements Action {

    public String defaultParam;
    @Override
    public String execute(RequestInfo requestInfo) {
        String fbfw = "";
        String mhlmkey = "";
        String wdid = "";

        //获取表单主字段的信息
        try {
            Property[] propertyArry = requestInfo.getMainTableInfo().getProperty();
            for (Property property : propertyArry) {
                String name = property.getName();

                //获取内外网的值判断是内网还是外网  fbfw  0是外网发布 1是内网发布1,0是内外网发布
                if ("fbfw".equals(name)) {
                    String value = Util.null2String(property.getValue());
                    fbfw = value;
                }
                //获取门户栏目的id  mhlm
                if ("mhlm".equals(name)) {
                    String value = Util.null2String(property.getValue());
                    mhlmkey = value;
                }
                if ("wd".equals(name)) {
                    String value = Util.null2String(property.getValue());
                    wdid = value;
                }

            }
            /**
             * wwml=外网目录
             * nwmlid=内网目录
             * nwwmlid=内外网目录ID
             * 外网发布=0
             * 内网发布=1
             * 微信公众号=2
             */
            String queryConfigSql = "";
            if ("0".equals(fbfw)||"0,2".equals(fbfw)||"2,0".equals(fbfw)) {
                //查询的列不同
                queryConfigSql = "select wwml from uf_nwwcddyjh where mlid = ?";
            }else if("1".equals(fbfw)||"1,2".equals(fbfw)||"2,1".equals(fbfw)){
                queryConfigSql = "select nwmlid from uf_nwwcddyjh where mlid = ?";
            } else if ("0,1".equals(fbfw) || "1,0".equals(fbfw)||"0,1,2".equals(fbfw)||"0,2,1".equals(fbfw)||"1,0,2".equals(fbfw)||"1,2,0".equals(fbfw)||"2,0,1".equals(fbfw)||"2,1,0".equals(fbfw)) {
                queryConfigSql = "select nwwmlid from uf_nwwcddyjh where mlid = ?";
            }else {
                queryConfigSql = "select nwwmlid from uf_nwwcddyjh where mlid = ?";
            }

            RecordSet queryConfigSqlSet = new RecordSet();

            boolean queryConfigSqlFlag = queryConfigSqlSet.executeQuery(queryConfigSql,mhlmkey);

            String mlid = "";
            //通过配置表去查目录id
            if (queryConfigSqlFlag && queryConfigSqlSet.next()) {
                if ("0".equals(fbfw)||"0,2".equals(fbfw)||"2,0".equals(fbfw)) {
                    //查询的列不同
                    mlid = queryConfigSqlSet.getString("wwml");
                }else if("1".equals(fbfw)||"1,2".equals(fbfw)||"2,1".equals(fbfw)){
                    mlid = queryConfigSqlSet.getString("nwmlid");
                } else if ("0,1".equals(fbfw) || "1,0".equals(fbfw)||"0,1,2".equals(fbfw)||"0,2,1".equals(fbfw)||"1,0,2".equals(fbfw)||"1,2,0".equals(fbfw)||"2,0,1".equals(fbfw)||"2,1,0".equals(fbfw)) {
                    mlid = queryConfigSqlSet.getString("nwwmlid");
                }else {
                    mlid = queryConfigSqlSet.getString("nwwmlid");
                }
            }

//            String updateSql = "Update docdetail Set seccategory = ? Where id = ? ";
//            RecordSet recordSet = new RecordSet();
            User user = new User(1);
            for (String s : wdid.split(",")) {
                DocManager docManager = new DocManager();
                //文档id
                docManager.setId(Integer.parseInt(s));
                //用户id
                docManager.setUserid(user.getUID());
                //⽤户类型
                docManager.setUsertype(user.getLogintype());
                //ip地址
                docManager.setClientAddress("127.0.0.1");
                //⽬标⽬录id
                docManager.setSeccategory(Integer.parseInt(mlid));
                //移动
                docManager.moveDoc();
                //默认共享刷新
                ShareManageDocOperation manager = new ShareManageDocOperation();
                manager.copyMoveDocShareBySec(Integer.parseInt(mlid),Integer.parseInt(s));
                new BaseBean().writeLog("ChangeDocStatusnwAction====>"+mlid+"property.getValue()===>"+s+"=======>");

            }
        } catch (Exception e) {
            e.printStackTrace();
            new BaseBean().writeLog("ChangeDocStatusnwAction异常："+e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }
}
